<template>
    <div class="config-manage-form">
        <avue-form ref="form" v-model="advsObj" :option="option" @reset-change="resetChange" @submit="submitSave">

        </avue-form>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                currentUrl: 'advs',
                advsObj: {},
                sizeValue: 'mini',
            }
        },
        computed: {
            option() {
                return {
                    size: this.sizeValue,
                    submitSize: this.sizeValue,
                    submitText: '保存',
                    printBtn: true,
                    labelWidth: 120,
                    column: [
                        {
                            label: "VIP",
                            prop: "vip",
                            type: 'number',
                            span: 24,
                            precision: 0,
                            minRows: 0,
                            maxRows: 100,
                            row: true,
                        }, {
                            label: "普通",
                            prop: "general",
                            type: 'number',
                            span: 24,
                            precision: 0,
                            minRows: 0,
                            maxRows: 100,
                            row: true,
                        }, {
                            label: "公益",
                            prop: "welfare",
                            type: 'number',
                            span: 24,
                            precision: 0,
                            minRows: 0,
                            maxRows: 100,
                            row: true,
                        }
                    ]
                }
            }
        },
        mounted() {
            this.systemConfigGetting()
        },
        methods: {
            systemConfigGetting() {
                const _this = this
                const params = {}
                _this.axios.post(_this.$API.ZHIHUAPI.systemConfigGetting + "/" + _this.currentUrl, _this.qs.stringify(
                    params)).then((res) => {
                    res = res.data
                    if (res.code === 10000) {
                        if (res.hasOwnProperty('data') && Object.keys(res.data).length > 0) {
                            _this.advsObj = res.data
                        } else {
                            _this.advsObj = {}
                        }
                    } else {
                        _this.$message({
                            showClose: false,
                            message: res.message,
                            type: 'error'
                        })
                        _this.advsObj = {}
                    }
                }).catch(() => {
                    _this.$message({
                        showClose: false,
                        message: '网络连接失败，请重试！',
                        type: 'error'
                    })
                    _this.advsObj = {}
                })
            },
            resetChange() {
                this.systemConfigGetting()
            },
            submitSave() {
                const _this = this
                const params = _this.advsObj
                _this.axios.post(_this.$API.ZHIHUAPI.systemConfigSetting + "/" + _this.currentUrl, _this.qs.stringify(
                    params)).then((res) => {
                    res = res.data
                    if (res.code === 10000) {
                        _this.$message({
                            showClose: false,
                            message: res.message,
                            type: 'success'
                        })
                        _this.systemConfigGetting()
                    } else {
                        _this.$message({
                            showClose: false,
                            message: res.message,
                            type: 'error'
                        })

                    }
                }).catch(() => {
                    _this.$message({
                        showClose: false,
                        message: '网络连接失败，请重试！',
                        type: 'error'
                    })
                })
            }
        }
    }
</script>
<style scoped>

</style>
